package com.mz.mattress.admin.api.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.mattress.admin.service.CityService;
import com.mz.mattress.api.common.Constants;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.City;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping(Constants.ADMIN_PATH + "city")
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping("/listPage")
    public Result<IPage<City>> listPage(@RequestParam(required = false) String province,
                                    @RequestParam(required = false) String city,
                                    @RequestParam(required = false) Integer status,
                                    @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                    @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return cityService.listPage(province, city, status, pageNo, pageSize);
    }

    @GetMapping("/listAll")
    public Result<Map<String, List<String>>> listAll() {
        return cityService.listAll();
    }

    @GetMapping("/{id}")
    public Result<City> detail(@PathVariable Integer id) {
        return cityService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody City city) {
        return cityService.add(city);
    }

    @PutMapping
    public Result update(@RequestBody City city) {
        return cityService.updateById(city);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return cityService.deleteByIds(ids);
    }

}
